﻿#ifndef BYTEUTIL_H
#define BYTEUTIL_H


#include <QByteArray>

#include "enum.h"

class ByteUtil
{
public:
    ByteUtil();


    // 获取字节的指定位的值
    static unsigned char getBits(unsigned char data, int low, int high);

    static unsigned short toUInt16(QByteArray& data, int offset, Endian endian = LittileEndian);
    static short toInt16(QByteArray& data, int offset, Endian endian = LittileEndian);
    static unsigned int toUInt32(QByteArray& data, int offset, Endian endian = LittileEndian);
    static int toInt32(QByteArray& data, int offset, Endian endian = LittileEndian);
    static unsigned long toUInt64(QByteArray& data, int offset, Endian endian = LittileEndian);
    static long toInt64(QByteArray& data, int offset, Endian endian = LittileEndian);
    static float toFloat(QByteArray& data, int offset, Endian endian = LittileEndian);
    static double toDouble(QByteArray& data, int offset, Endian endian = LittileEndian);
};

#endif // BYTEUTIL_H
